package com.spark.check

import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.spark.check.model.TaskModel
import com.spark.common.BaseFragment
import com.spark.common.Const
import kotlinx.android.synthetic.main.frag_whole_tasks_item.*

/**
 * 全部任务的子条目
 */
class WholeTasksItemFragment : BaseFragment() {
    private var index = 0
    private lateinit var tasksAdapter: TasksAdpater

    companion object {
        fun newInstance(index: Int): WholeTasksItemFragment {
            val fragment = WholeTasksItemFragment()
            val args = Bundle()
            args.putInt(Const.tag_index, index)
            fragment.arguments = args
            return fragment
        }
    }

    @SuppressLint("MissingSuperCall")
    override fun onAttach(context: Context?) {
        super.onAttach(context)
        index = arguments?.getInt(Const.tag_index) ?: 0
    }

    override fun contentResId(): Int {
        return R.layout.frag_whole_tasks_item
    }

    @SuppressLint("MissingSuperCall")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        tasksAdapter = TasksAdpater(R.layout.item_task)
        recy_tasks.adapter = tasksAdapter
        recy_tasks.layoutManager = LinearLayoutManager(activity)
        tasksAdapter.addData(TaskModel.mock())

        refresh_layout.setOnRefreshListener { }
        refresh_layout.setOnLoadmoreListener { }
    }
}
